set(TARGET my_lib)

cmake_minimum_required(VERSION 3.10)
project(${TARGET})

# 设置编译选项
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -g")

# 查找 OpenCV
find_package(OpenCV REQUIRED)

# 让静态库编译时也生成位置无关的代码(PIC), 这样才能装在动态库里
# set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# 添加动态库
add_library(${TARGET} ${LIB_TYPE} my_lib.cpp substract.cpp)
target_include_directories(${TARGET} PUBLIC
    ${OpenCV_INCLUDE_DIRS}
    ${CMAKE_SOURCE_DIR}
    include
)

# 定义导出宏（仅编译库时生效）
if(${LIB_TYPE} EQUAL SHARED)
    target_compile_definitions(${TARGET} PRIVATE MYLIB_EXPORTS)
endif()

# 链接 OpenCV
target_link_libraries(${TARGET} PRIVATE ${OpenCV_LIBS})

# 设置输出目录
set_target_properties(${TARGET} PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
)
